package com.guli.mall.pms.controller.frontWebController;

import com.guli.common.constant.AuthServerConstant;
import com.guli.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/*
 * @Author 罗
 * @date 2020/10/10 - 10:45 上午
 */
@RestController
@RequestMapping("/index")
public class IndexController {

    @GetMapping("/getLoginUserInfoBySession")
    @ResponseBody
    public R hello(HttpServletRequest request) {

        Object hello = request.getSession().getAttribute(AuthServerConstant.LOGIN_USER_SESSION);

        return R.ok().put("loginUser", hello);
    }

    @GetMapping("/logout")
    @ResponseBody
    public R logout(HttpSession session) {
        session.removeAttribute(AuthServerConstant.LOGIN_USER_SESSION);
        return R.ok();
    }
}
